﻿using FrameworkTemplate.Windows.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace FrameworkTemplate.Windows
{
    /// <summary>
    /// 主窗口的View Model
    /// </summary>
    public class MainWindowViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// 当前已打开的子窗口字典, 
        /// 注意:只要带有 public get 方法的属性都可以在窗口中使用Binding进行数据绑定
        /// </summary>
        public Dictionary<string, Window> windows { get; private set; }

        public MainWindowViewModel()
        {
            windows = new Dictionary<string, Window>();
        }
        ICommand openAccountWindowCmd;
        public ICommand OpenAccountWindowCmd { get
            {//当命令为null时 new 命令对象
                return openAccountWindowCmd ?? (openAccountWindowCmd = new OpenAccountWindow());
            }
        }

        ICommand openScriptWindowCmd;
        public ICommand OpenScriptWindowCmd
        {
            get
            {
                return openScriptWindowCmd ?? (openScriptWindowCmd = new OpenScriptWindow());
            }
        }
        ICommand openSettingsWindowCmd;
        public ICommand OpenSettingsWindowCmd
        {
            get
            {
                return openSettingsWindowCmd ?? (openSettingsWindowCmd = new OpenSettingsWindow());
            }
        }
        ICommand openLoginWindowCmd;
        public ICommand OpenLoginWindowCmd
        {
            get
            {
                return openLoginWindowCmd ?? (openLoginWindowCmd = new OpenLoginWindow());
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        // This method is called by the Set accessor of each property.
        // The CallerMemberName attribute that is applied to the optional propertyName
        // parameter causes the property name of the caller to be substituted as an argument.
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
